import { myAxios } from "@/request";

interface UserRegisterRequest {
  userAccount: string;
  userPassword: string;
  checkPassword: string;
}

export interface UserLoginRequest {
  userAccount: string;
  userPassword: string;
}

export interface UserClearVO {
  id: string;
  username: string;
  userAccount: string;
  userRole: number;
  avatarUrl: string;
  gender: number;
  phone: string;
  email: string;
  userStatus: number;
  createTime: Date;
}

/**
 * 用户注册
 * @param params
 */
export const userRegister = async (params: UserRegisterRequest) => {
  return await myAxios.request({
    method: "POST",
    url: "/api/user/register",
    data: params,
  });
};

/**
 * 用户登录
 * @param params
 */
export const userLogin = async (params: UserLoginRequest) => {
  return await myAxios.request({
    method: "POST",
    url: "/api/user/login",
    data: params,
  });
};

/**
 * 用户注销
 * @param params
 */
export const userLogout = async () => {
  return await myAxios.request({
    method: "POST",
    url: "/api/user/logout",
  });
};

/**
 * 获取当前用户
 */
export const getCurrentUser = async () => {
  return await myAxios.request({
    method: "GET",
    url: "/api/user/currentUser",
  });
};

/**
 * 获取用户列表
 */
export const userSearch = async (username: any, userAccount: any) => {
  return await myAxios.request({
    method: "GET",
    url: "/api/user/search",
    params: {
      username,
      userAccount,
    },
  });
};

/**
 * 删除用户
 * @param id
 */
export const userDel = async (id: string) => {
  return await myAxios.request({
    method: "POST",
    url: "/api/user/delete",
    //因为后端使用的body接受id，所以要将id作为整个json对象传递
    data: id,
    headers: {
      "Content-Type": "application/json",
    },
  });
};
